<template>
  <div class="app-container">

    <el-table v-loading="loading" :data="gaizhangCertificateList" @selection-change="handleSelectionChange">
      <el-table-column label="编号" align="center" prop="idx" />
      <el-table-column label="课程表" align="center" prop="urlClassTable" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlClassTable" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="报名册" align="center" prop="urlApplication" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlApplication" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="签到表" align="center" prop="urlSign" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlSign" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="培训评估报告" align="center" prop="urlInvalue" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlInvalue" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="安全培训合格证明" align="center" prop="urlCertificate" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlCertificate" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="成绩汇总表" align="center" prop="gradeSet" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.gradeSet" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="考场情况记录表" align="center" prop="examplaceRecord" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.examplaceRecord" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            style="width: 40px;"
            @click="handleUpdate(scope.row)"
          >查看</el-button>

          <el-button
            size="mini"
            type="primary"
            style="width: 60px;"
            @click="checkStudentInfo(scope.row)"
          >学员信息</el-button>

          <el-button
            size="mini"
            type="success"
            style="width: 40px;"
            @click="gaizhang(scope.row)"
          >盖章</el-button>

        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改盖章对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form :inline="true" ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="编号" prop="idx">
          <el-input v-model="form.idx" placeholder="请输入编号" />
        </el-form-item>
        <el-form-item label="培训班期次" prop="classTerm">
          <el-input v-model="form.classTerm" placeholder="请输入培训班期次" />
        </el-form-item>
        <el-form-item label="考试期次" prop="examTerm">
          <el-input v-model="form.examTerm" placeholder="请输入考试期次" />
        </el-form-item>
        <el-form-item v-if="form.qualifiedType == 1 || form.qualifiedType == 2" label="理论考试时间" prop="examTime">
          <el-date-picker clearable
            v-model="form.examTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择理论考试时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item v-if="form.qualifiedType == 1 || form.qualifiedType == 2" label="理论补考时间" prop="reviewTime">
          <el-date-picker clearable
            v-model="form.reviewTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择理论补考时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item v-if="form.qualifiedType == 3" label="实操考试时间" prop="operationExamTime">
          <el-date-picker clearable
            v-model="form.operationExamTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择实操考试时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item v-if="form.qualifiedType == 3" label="实操补考时间" prop="operationReviewTime">
          <el-date-picker clearable
            v-model="form.operationReviewTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择实操补考时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="课程表" prop="urlClassTable">
          <image-upload v-model="form.urlClassTable"/>
        </el-form-item>
        <el-form-item label="报名册" prop="urlApplication">
          <image-upload v-model="form.urlApplication"/>
        </el-form-item>
        <el-form-item label="签到表" prop="urlSign">
          <image-upload v-model="form.urlSign"/>
        </el-form-item>
        <el-form-item label="培训评估报告" prop="urlInvalue">
          <image-upload v-model="form.urlInvalue"/>
        </el-form-item>
        <el-form-item label="安全培训合格证明" prop="urlCertificate">
          <image-upload v-model="form.urlCertificate"/>
        </el-form-item>
        <el-form-item label="成绩汇总表" prop="gradeSet">
          <image-upload v-model="form.gradeSet"/>
        </el-form-item>
        <el-form-item label="考场情况记录表" prop="examplaceRecord">
          <image-upload v-model="form.examplaceRecord"/>
        </el-form-item>
        <el-form-item label="培训计划申请" prop="trainplanApplication">
          <file-upload v-model="form.trainplanApplication"/>
        </el-form-item>

        <el-form-item label="考试申请表pdf" prop="examApplicationPdf">
          <file-upload v-model="form.examApplicationPdf"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGaizhangCertificate, getGaizhangCertificate, delGaizhangCertificate, addGaizhangCertificate, updateGaizhangCertificate } from "@/api/exam/gaizhangCertificate";

export default {
  name: "GaizhangCertificate",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 盖章表格数据
      gaizhangCertificateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 跳转到学生列表
    checkStudentInfo(row) {
      const ids = row.id;
        window.location.href = "../exam/examApplicationQualified?examPassCertificateId=" + ids;
    },
    gaizhang(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确定盖章？').then(function() {
        return updateGaizhangCertificate(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("盖章成功");
      }).catch(() => {});
    },
    /** 查询盖章列表 */
    getList() {
      this.loading = true;
      listGaizhangCertificate(this.queryParams).then(response => {
        this.gaizhangCertificateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        idx: null,
        classTerm: null,
        examTerm: null,
        examTime: null,
        reviewTime: null,
        operationExamTime: null,
        operationReviewTime: null,
        auditId: null,
        approvalId: null,
        examOperationSheet: null,
        approvalProcessSign: null,
        isDeleted: null,
        createId: null,
        updateId: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加盖章";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGaizhangCertificate(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改盖章";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGaizhangCertificate(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGaizhangCertificate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除盖章编号为"' + ids + '"的数据项？').then(function() {
        return delGaizhangCertificate(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('exam/gaizhangCertificate/export', {
        ...this.queryParams
      }, `gaizhangCertificate_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
